package com.继承.基础;
class Teacher{
    private String name;

    Teacher(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class Student{
    private String name;
    Student(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class School{
    private Teacher[] teachers;
    private Student[] students;
    private int teacherCount =0;
    private int studentCount =0;

    void create(int teacherNum,int studentNum){
        teachers =new Teacher[teacherNum];
        students =new Student[studentNum];
    }
    void addTeacher(Teacher teacher){
        if(teacherCount<teachers.length){
            teachers[teacherCount]= teacher;
            teacherCount++;
        }else{
            System.out.println("教师数组满了");
        }
    }

    void addStudent(Student student){
        if(studentCount<students.length){
            students[studentCount] =student;
            studentCount++;
        }else{
            System.out.println("学生数组满了");
        }
    }

    public Teacher[] getTeachers() {
        return teachers;
    }

    public Student[] getStudents() {
        return students;
    }
}
public class 组合 {
    public static void main(String[] args) {
        School school = new School();
        school.create(3,3);
        //分配教师
        Teacher teacher1 = new Teacher("王菲");
        Teacher teacher2 = new Teacher("王芳");

        school.addTeacher(teacher1);
        school.addTeacher(teacher2);
        //分配学生
        Student student1 =new Student("小明");
        Student student2 = new Student("小红");

        school.addStudent(student1);
        school.addStudent(student2);

        //打印信息
        for(Teacher teacher :school.getTeachers()){
            if(teacher!=null) {
                System.out.println("教师：" + teacher.getName());
            }
        }
        for(Student student : school.getStudents()){
            if(student!=null) {
                System.out.println("学生：" + student.getName());
            }
        }

    }
}
